<script>
import {defineComponent} from 'vue'
import {mapState, mapGetters, mapActions, mapMutations} from "vuex";

export default defineComponent({
  name: "Count",
  data() {
    return {
      n: 1
    }
  },
  methods: {
    /*increment() {
      //组件里面调用this.$store.dispatch(参数一：类型 参数二：值)联系actions
      this.$store.dispatch("increment", this.n)

      // this.$store.commit("ICCREMENT",this.n) 直接调用commit联系mutations
    },
    decrement() {
      //组件里面调用this.$store.dispatch(参数一：类型 参数二：值)联系actions
      this.$store.dispatch("decrement", this.n)

      // this.$store.commit("DECREMENT",this.n) 直接调用commit联系mutations

    },
    incrementOdd() {
      //组件里面调用this.$store.dispatch(参数一：类型 参数二：值)联系actions
      this.$store.dispatch("incrementOdd", this.n)

    },
    incrementWait() {
      //组件里面调用this.$store.dispatch(参数一：类型 参数二：值)联系actions
      this.$store.dispatch("incrementWait", this.n)

    },

    */
    //mapActions()：用于帮助我们映射actions中的方法[数组写法]
    ...mapActions(["increment", "decrement", "incrementOdd", "incrementWait"]),

     //mapActions()：用于帮助我们映射actions中的方法[对象写法]
    /*...mapActions({increment:"increment",decrement:"decrement",incrementOdd:"incrementOdd", incrementWait:"incrementWait"}),*/


    //mapMutations()：用于帮助我们映射Mutations中的方法[对象写法]
    ...mapMutations({increment:"ICCREMENT",decrement:"DECREMENT"}),

    //mapMutations()：用于帮助我们映射Mutations中的方法[数组写法]
    /*...mapMutations(["ICCREMENT", "DECREMENT"]),*/


  },
  computed: {
    //靠程序员自己亲自写计算属性获取store.state和store.getters
    /*
    sum() {
      return this.$store.state.sum
    },
    school() {
      return this.$store.state.school
    },
    subject() {
      return this.$store.state.subject
    },
    bingSum() {
      return this.$store.getters.bingSum
    },
     */

    // 靠程序员借助mapState生成计算属性，从state中获取数据(对象写法)
    /*...mapState({sum:"sum",school:"school",subject:"subject"})*/

    // 靠程序员借助mapState生成计算属性，从state中获取数据(数组写法)
    ...mapState(['sum', 'school', 'subject']),


    // 靠程序员借助Getters生成计算属性，从getters中获取数据(对象写法)
    ...mapGetters({bingSum: 'bingSum'})

    // 靠程序员借助Getters生成计算属性，从getters中获取数据(数组写法)
    // ...mapGetters(['bingSum'])

  }

})
</script>
<template>
  <div>
    <h1>当前求和为:{{ sum }}</h1>
    <h1>放大10倍和:{{ bingSum }}</h1>
    <h1>我在{{ school }}学习{{ subject }}</h1>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increment(n)">+</button>
    <button @click="decrement(n)">-</button>
    <button @click="incrementOdd(n)">求和为奇数再加</button>
    <button @click="incrementWait(n)">等等再加</button>
  </div>
</template>

<style scoped lang="less">

</style>
